package club.yunqiang.zbs.starter;

import club.yunqiang.zbs.bean.BeanFactory;
import club.yunqiang.zbs.core.ClassScanner;
import club.yunqiang.zbs.web.handler.HandlerManager;
import club.yunqiang.zbs.web.server.TomcatServer;
import org.apache.catalina.LifecycleException;

import java.io.IOException;
import java.util.List;

/**
 * @author 张云强
 * @date 2019/7/6
 */
public class MiniApplication {

    public static void run(Class<?> clazz, String[] args){
        System.out.println("Hello mini-spring!");
        TomcatServer tomcatServer = new TomcatServer(args);
        try {
            tomcatServer.startServer();
            List<Class<?>> classes = ClassScanner.scanClasses(clazz.getPackage().getName());
            BeanFactory.initBean(classes);
            HandlerManager.resolveMappingHandler(classes);
            classes.forEach(it -> System.out.println(it.getName()));
        } catch (LifecycleException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
